local PartnerRelation = class("PartnerRelation")
local PartnerHelper = require("app.partner.PartnerHelper")
function PartnerRelation:ctor()

end

function PartnerRelation:initWithId(id)
    self._id = tonumber(id)
    local conf = GD:queryPartnerRelationById(self._id)
    self._conf = conf
    local ps = string.split(self._conf.partner, ";")
    self._partnerId1 = tonumber(ps[1])
    self._partnerId2 = tonumber(ps[2])
    self:initProps()
end

function PartnerRelation:initWithConf(conf)
    self._conf = conf
    self._id = tonumber(self._conf.ID)
    local ps = string.split(self._conf.partner, ";")
    self._partnerId1 = tonumber(ps[1])
    self._partnerId2 = tonumber(ps[2])
    --self:initProps()
end



--1|21#80|11#250|72#80;2|21#150|11#450|72#120;3|21#250|11#700|72#200;4|21#400|11#1200|72#350;5|21#600|11#1700|72#500
--[[
function PartnerRelation:initProps()
    local parseStr
    if UD.player.classID == Enums.Profession.warrior or 
        UD.player.classID == Enums.Profession.hunter or
        UD.player.classID == Enums.Profession.rouge then
            parseStr = self._conf.physicalAttrShow
    else
        parseStr = self._conf.magicAttrShow
    end
    local qProps = string.split(parseStr, ";")

    local p = {}
    for k, v in pairs(qProps) do
        local tempArr = string.split(v, "|")
        if #tempArr >= 2 then
            local props = {}
            for i =2, #tempArr do
                local spArr = string.split(tempArr[i], "#")
                table.insert(props, {spArr[1], tonumber(spArr[2])})
            end
            p[tonumber(tempArr[1])] = props
        else
            print("error ====>>> ", self._id, parseStr)
        end
    end
    self._qualityProps = p
end
--]]

-- 返回羁绊点品质  partner1 品质  partner2 品质 
function PartnerRelation:getQuality()
    local p1 = UD.partnersData:getPartnerById(self._partnerId1)
    local p2 = UD.partnersData:getPartnerById(self._partnerId2)

    local q1 = 0
    local q2 = 0
    if p1 and p1:isHave() then
        q1 = p1:getQuality()
    end
    if p2 and p2:isHave() then
        q2 = p2:getQuality()
    end

    local curQ = q1
    local nextQ = q2
    if q1 > q2 then
        curQ = q2
        nextQ = q1
    end


    return curQ, nextQ, q1, q2
end

--这些属性都移到partner身上啦
--[[
function PartnerRelation:getShowProps(q)
    if not q then
        q = self:getQuality()
    end
    return self._qualityProps[q] or {}
end
--]]

function PartnerRelation:getUpgradeTip()
    local p1 = UD.partnersData:getPartnerById(self._partnerId1)
    local p2 = UD.partnersData:getPartnerById(self._partnerId2)
    if p1 and p2 then
        if p1:isHave() and p2:isHave() then
            local q1 = p1:getQuality()
            local q2 = p2:getQuality()
            if q1 == q2 then
                if q1 >= 5 then
                    return ""
                else
                    return string.format(L("RelationUpgradeTip1"), p1:getName(), p2:getName(), L(Enums.QualityColorString[q1 + 1]))
                end
            else
                local lowP , lowQ
                if q1 > q2 then
                    lowP = p2
                    lowQ = q2
                else
                    lowP = p1
                    lowQ = q1
                end
                return string.format(L("RelationUpgradeTip2"), lowP:getName(), L(Enums.QualityColorString[lowQ + 1]))
            end
        else
            if not p1:isHave() and not p2:isHave() then
                return string.format(L("RelationUpgradeTip3"), p1:getName(), p2:getName())
            else
                local notUnlockP 
                if p1:isHave() then
                    notUnlockP = p2
                else
                    notUnlockP = p1
                end
                return string.format(L("RelationUpgradeTip4"), notUnlockP:getName())
            end
        end
    end
    return ""
end


function PartnerRelation:getScore(quality)
    local q = quality or self:getQuality()
    if q == 0 then
        return 0
    end
    return PartnerHelper.getPartnerRelationScoreByQuality(q)
end

--获得颜色名字
function PartnerRelation:getColorString(quality)
    local q = quality or self:getQuality()
    if q == 0 then
        q = 1
    end
    return PartnerHelper.getPartnerRelationColorStringByQuality(q)
end

--获得颜色
function PartnerRelation:getColor(quality)
    local q = quality or self:getQuality()
    if q == 0 then
        q = 1
    end

    return PartnerHelper.getPartnerRelationColorByQuality(q)
end

function PartnerRelation:getPos()
    return tonumber(self._conf.position or 1)
end
return PartnerRelation